<?php

namespace App\Admin\Controllers;

use App\Admin\Actions\Post\Restore;
use App\Admin\Repositories\UserAdmin;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class UserAdminController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new UserAdmin(), function (Grid $grid) {
            $grid->filter(function ($filter) {

                // 范围过滤器，调用模型的`onlyTrashed`方法，查询出被软删除的数据。
                $filter->scope('trashed', '回收站')->onlyTrashed();

            });
            $grid->actions(function (Grid\Displayers\Actions $actions) {
                if (request('_scope_') == 'trashed') {
                    $actions->append(new Restore(\App\Models\UserAdmin::class));
                }
            });

            $grid->column('id')->sortable();
            $grid->column('account');
            $grid->column('pwd');
            $grid->column('real_name');
            $grid->column('birthday');
            $grid->column('card_id');
            $grid->column('nickname');
            $grid->column('avatar')->image('',100,100);
            $grid->column('tel');
            $grid->column('add_time');
            $grid->column('add_ip');
            $grid->column('last_time');
            $grid->column('last_ip');
            $grid->column('address');
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new UserAdmin(), function (Show $show) {
            $show->field('id');
            $show->field('account');
            $show->field('pwd');
            $show->field('real_name');
            $show->field('birthday');
            $show->field('card_id');
            $show->field('nickname');
            $show->field('avatar');
            $show->field('tel');
            $show->field('add_time');
            $show->field('add_ip');
            $show->field('last_time');
            $show->field('last_ip');
            $show->field('address');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new UserAdmin(), function (Form $form) {
            $form->display('id');
            $form->text('account');
            $form->text('pwd');
            $form->text('real_name');
            $form->text('birthday');
            $form->text('card_id');
            $form->text('nickname');
            $form->text('avatar');
            $form->text('tel');
            $form->text('add_time');
            $form->text('add_ip');
            $form->text('last_time');
            $form->text('last_ip');
            $form->text('address');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
